﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fortuitus.Core
{
    public class EditableVector : Vector
    {
        /// <summary>
        /// Applies a function to each number in the vector.
        /// </summary>
        /// <param name="function">The function to apply.</param>
        public void Apply(Func<double, double> function)
        {
            
            for (int i = 0; i < _numbers.Length; i++)
            {
                _numbers[i] = function(_numbers[i]);
            }
            base.InvalidateMetricCache();
            OnChanged();
        }

        /// <summary>
        /// Indexer property to read and write a number at a specific index.
        /// </summary>
        /// <param name="indx"></param>
        /// <returns></returns>
        public new double this[int indx]
        {
            get
            {
                return base[indx];
            }
            set
            {
                if (_numbers[indx] != value)
                {
                    _numbers[indx] = value;
                    base.InvalidateMetricCache();
                    OnChanged();
                }
            }
        }

    
        /// <summary>
        /// The standard constructor
        /// </summary>
        /// <param name="numbers">The number to initialize teh vector.</param>
        public EditableVector(IEnumerable<double> numbers)
            : base(numbers)
        {
        }
    }
}
